Completed
Push — master ( ac4b4e...bdacbd )
by Gianluca
12s
created

test.js ➔ ... ➔ describe(ꞌAuthꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 2
b 0
f 0
nc 1
dl 0
loc 29
rs 9.65
nop 0
1
const chai = require('chai');
2
const expect = chai.expect;
3
const jsonPattern = require('chai-json-pattern');
4
const sinon = require('sinon');
5
const { Client: SDKClient } = require('../bin/index');
6
7
const {
8
    projectSchema,
9
    blockSchema,
10
    rowSchema,
11
    columnSchema,
12
    contentSchema,
13
    paginatedProjectSchema
14
} = require('./Schemas');
15
16
chai.use(jsonPattern.default);
17
18
// Test clients setup
19
var authenticatedTestClient = null;
20
var unauthenticatedTestClient = null;
21
async function getUnauthenticatedTestClient() {
22
    if (!unauthenticatedTestClient) {
23
        /** global: SDKClient */
24
        unauthenticatedTestClient = new SDKClient('http://localhost:3000');
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
    }
26
27
    return unauthenticatedTestClient;
28
}
29
async function getAuthenticatedTestClient() {
30
    if (!authenticatedTestClient) {
31
        /** global: SDKClient */
32
        authenticatedTestClient = new SDKClient('http://localhost:3000');
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
33
34
        const username = '[email protected]';
35
        const password = 'gian6280';
36
37
        await authenticatedTestClient.authenticate(username, password);
38
    }
39
40
    return authenticatedTestClient;
41
}
42
43
describe('Wrapper', function() {
44
    afterEach(() => {
45
        sinon.restore();
46
    });
47
48
    describe('Api Url', function() {
49
        it('should get default api url if no url is passed in constructor', function() {
50
            /** global: SDKClient */
51
            const client = new SDKClient();
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
52
53
            expect(client.apiUrl).to.equal('https://api.proposalpage.com');
54
        });
55
        it('should get passed url if a url is passed in constructor', function() {
56
            /** global: SDKClient */
57
            const client = new SDKClient('https://example.com');
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
58
59
            expect(client.apiUrl).to.equal('https://example.com');
60
        });
61
    });
62
63
    describe('Token', function() {
64
        it('should not have a default token set', function() {
65
            /** global: SDKClient */
66
            const client = new SDKClient();
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
67
68
            expect(client.token).to.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to expect(client.token).to.be.undefined is not used.
Loading history...
69
        });
70
        it('should get the token that has been set', function() {
71
            /** global: SDKClient */
72
            const client = new SDKClient();
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
73
74
            client.token = 'token';
75
76
            expect(client.token).to.equal('token');
77
        });
78
    });
79
});
80
81
describe('Api Responses', function() {
82
    afterEach(() => {
83
        sinon.restore();
84
    });
85
86
    describe('Auth', function() {
87
        describe('Token', function() {
88
            it('should return token', async function() {
89
                const client = await getUnauthenticatedTestClient();
90
91
                const username = '[email protected]';
92
                const password = 'teste';
93
94
                const response = await client.authenticate(username, password);
95
96
                expect(response.statusCode).to.equal(200);
97
                expect(response.json).to.matchPattern(`{
98
                    "token": String,
99
                }`);
100
            });
101
        });
102
103
        describe('Me', function() {
104
            it('should return logged user id', async function() {
105
                const client = await getAuthenticatedTestClient();
106
                const response = await client.authMe();
107
108
                expect(response.statusCode).to.equal(200);
109
                expect(response.json).to.matchPattern(`{
110
                    "id": String,
111
                }`);
112
            });
113
        });
114
    });
115
116
    describe('Project', function() {
117
        var testProjectId = null;
118
119
        describe('Create', function() {
120
            it('should create and return a project', async function() {
121
                const client = await getAuthenticatedTestClient();
122
                const response = await client.createProject({
123
                    title: 'New Project',
124
                    blocks: [],
125
                });
126
127
                const responseBody = response.json;
128
129
                expect(response.statusCode).to.equal(201);
130
                expect(responseBody).to.matchPattern(projectSchema);
131
                expect(responseBody.title).to.equal('New Project');
132
                expect(responseBody.blocks).to.be.empty;
0 ignored issues
show
introduced by
The result of the property access to expect(responseBody.blocks).to.be.empty is not used.
Loading history...
133
134
                testProjectId = responseBody._id;
135
            });
136
        });
137
138
        describe('List', function() {
139
            it('should list user projects paginated', async function() {
140
                const client = await getAuthenticatedTestClient();
141
                const response = await client.listProjects();
142
143
                const responseBody = response.json;
144
                const projects = responseBody.items;
145
146
                expect(response.statusCode).to.equal(200);
147
                expect(responseBody).to.matchPattern(paginatedProjectSchema);
148
                projects.forEach(project => {
149
                    expect(project).to.matchPattern(projectSchema);
150
                });
151
            });
152
153
            it('should list user projects paginated in a specific page', async function() {
154
                const client = await getAuthenticatedTestClient();
155
                const response = await client.listProjects(2, 3);
156
157
                const responseBody = response.json;
158
                const projects = responseBody.items;
159
160
                expect(response.statusCode).to.equal(200);
161
                expect(responseBody).to.matchPattern(paginatedProjectSchema);
162
                expect(responseBody.page).to.equal(2);
163
                expect(responseBody.limit).to.equal(3);
164
                projects.forEach(project => {
165
                    expect(project).to.matchPattern(projectSchema);
166
                });
167
            });
168
169
            it('should list user projects paginated with a specific quantity of items per page', async function() {
170
                const client = await getAuthenticatedTestClient();
171
                const response = await client.listProjects(2);
172
173
                const responseBody = response.json;
174
                const projects = responseBody.items;
175
176
                expect(response.statusCode).to.equal(200);
177
                expect(responseBody).to.matchPattern(paginatedProjectSchema);
178
                expect(responseBody.page).to.equal(2);
179
                projects.forEach(project => {
180
                    expect(project).to.matchPattern(projectSchema);
181
                });
182
            });
183
184
            it('should list user projects paginated with a specific title search', async function() {
185
                const client = await getAuthenticatedTestClient();
186
                const response = await client.listProjects(1, 6, 'Project title that does not exist');
187
188
                const responseBody = response.json;
189
                const projects = responseBody.items;
190
191
                expect(response.statusCode).to.equal(200);
192
                expect(responseBody).to.matchPattern(`{
193
                    "items": Array,
194
                    "totalItems": Number,
195
                    "page": Number,
196
                    "limit": Number,
197
                    "pages": Number,
198
                    "defaultCover": String,
199
                }`);
200
                expect(responseBody.page).to.equal(1);
201
                expect(responseBody.limit).to.equal(6);
202
                expect(responseBody.items.length).to.equal(0);
203
                projects.forEach(project => {
204
                    expect(project).to.matchPattern(`{
205
                        "_id": String,
206
                        "title": String,
207
                        "fonts": Array,
208
                        "publish": Boolean,
209
                        "secure": Boolean,
210
                        "countViews": Number,
211
                        "timeViews": Number,
212
                        "priority": Number,
213
                        "blocks": Array,
214
                        "userId": String,
215
                        "accountId": String,
216
                        "token": String,
217
                        "slug": String,
218
                        "publishURL": String,
219
                        "createdAt": String,
220
                        "updatedAt": String,
221
                        "__v": Number,
222
                        "password"?: String OR null,
223
                        "lastView"?: String,
224
                    }`);
225
                });
226
            });
227
        });
228
229
        describe('Retrieve', function() {
230
            it('should retrieve a existing project', async function() {
231
                const client = await getAuthenticatedTestClient();
232
                const response = await client.listProject(testProjectId);
233
234
                expect(response.statusCode).to.equal(200);
235
                expect(response.json).to.matchPattern(projectSchema);
236
            });
237
        });
238
239
        describe('Update', function() {
240
            it('should update a existing project', async function() {
241
                const client = await getAuthenticatedTestClient();
242
                const response = await client.updateProject(testProjectId, {
243
                    title: 'Updated Project Title',
244
                });
245
246
                const responseBody = response.json;
247
248
                expect(response.statusCode).to.equal(200);
249
                expect(responseBody).to.matchPattern(projectSchema);
250
                expect(responseBody.title).to.equal('Updated Project Title');
251
            });
252
        });
253
254
        describe('Clone', function() {
255
            it('should clone a project and return it', async function() {
256
                const client = await getAuthenticatedTestClient();
257
                const response = await client.cloneProject(testProjectId);
258
259
                const responseBody = response.json;
260
261
                expect(response.statusCode).to.equal(200);
262
                expect(responseBody).to.matchPattern(projectSchema);
263
                expect(responseBody.title).to.equal('Updated Project Title');
264
                expect(responseBody.blocks).to.be.empty;
0 ignored issues
show
introduced by
The result of the property access to expect(responseBody.blocks).to.be.empty is not used.
Loading history...
265
            });
266
        });
267
268
        describe('Password', function() {
269
            it('should set project password', async function() {
270
                const client = await getAuthenticatedTestClient();
271
                const response = await client.setProjectPassword(testProjectId, 'password');
272
273
                const responseBody = response.json;
274
275
                expect(response.statusCode).to.equal(200);
276
                expect(responseBody).to.matchPattern(projectSchema);
277
                expect(responseBody.password).to.equal('password');
278
            });
279
280
            it('should check project password', async function() {
281
                const client = await getUnauthenticatedTestClient();
282
283
                const correctPasswordResponse = await client.checkProjectPassword(
284
                    testProjectId,
285
                    'password'
286
                );
287
                expect(correctPasswordResponse.statusCode).to.equal(200);
288
289
                const incorrectPasswordResponse = await client.checkProjectPassword(
290
                    testProjectId,
291
                    'password1'
292
                );
293
                expect(incorrectPasswordResponse.statusCode).to.equal(401);
294
            });
295
        });
296
297
        describe('Publish', function() {
298
            it('should set project publish to true', async function() {
299
                const client = await getAuthenticatedTestClient();
300
                const response = await client.publishProject(testProjectId);
301
302
                const responseBody = response.json;
303
304
                expect(response.statusCode).to.equal(200);
305
                expect(responseBody).to.matchPattern(projectSchema);
306
                expect(responseBody.publish).to.equal(true);
307
            });
308
        });
309
310
        describe('Secure', function() {
311
            it('should set project secure to true', async function() {
312
                const client = await getAuthenticatedTestClient();
313
                const response = await client.secureProject(testProjectId);
314
315
                const responseBody = response.json;
316
317
                expect(response.statusCode).to.equal(200);
318
                expect(responseBody).to.matchPattern(projectSchema);
319
                expect(responseBody.secure).to.equal(true);
320
            });
321
        });
322
323
        describe('Cover', function() {
324
            it('should generate project cover', async function() {
325
                const client = await getAuthenticatedTestClient();
326
                const response = await client.generateProjectCover(testProjectId);
327
328
                expect(response.statusCode).to.equal(200);
329
            });
330
        });
331
332
        describe('Copy', function() {
333
            it('should generate project based on a default template', async function() {
334
                const templateId = '5cb47ec98497e9001ad9a1b2';
335
                const client = await getAuthenticatedTestClient();
336
                const response = await client.createProjectFromTemplate(templateId);
337
338
                const responseBody = response.json;
339
340
                expect(response.statusCode).to.equal(200);
341
                expect(responseBody).to.matchPattern(projectSchema);
342
            });
343
        });
344
345
        describe('Customer', function() {
346
            it('should set a customer on the project', async function() {
347
                const client = await getAuthenticatedTestClient();
348
                const response = await client.updateProject(testProjectId, {
349
                    customer: {
350
                        name: 'Gianluca Bine',
351
                        email: '[email protected]'
352
                    }
353
                });
354
355
                const responseBody = response.json;
356
357
                expect(response.statusCode).to.equal(200);
358
                expect(responseBody).to.matchPattern(projectSchema);
359
                expect(responseBody.customer.name).to.equal('Gianluca Bine');
360
                expect(responseBody.customer.email).to.equal('[email protected]');
361
            })
362
        });
363
364
        describe('Accept', function() {
365
            it('should send the confirm acceptance emails', async function() {
366
                const client = await getAuthenticatedTestClient();
367
                const response = await client.acceptProject(testProjectId);
368
369
                expect(response.statusCode).to.equal(200);
370
            })
371
        });
372
373
        describe('View and Notify', function() {
374
            it('should update project last view time and send email with notification only if is not the project owner viewing', async function() {
375
                const client = await getUnauthenticatedTestClient();
376
                const response = await client.viewProjectAndNotify(testProjectId);
377
378
                // const responseBody = response.json;
379
380
                expect(response.statusCode).to.equal(200);
381
                // expect(responseBody.emailSent).to.equal(true);
382
            });
383
        });
384
385
        describe('Templates', function() {
386
            it('should list templates thar the user can use paginated', async function() {
387
                const client = await getAuthenticatedTestClient();
388
                const response = await client.listTemplates();
389
390
                const responseBody = response.json;
391
                const templates = responseBody.items;
392
393
                expect(response.statusCode).to.equal(200);
394
                expect(responseBody).to.matchPattern(paginatedProjectSchema);
395
                templates.forEach(template => {
396
                    expect(template).to.matchPattern(projectSchema);
397
                });
398
            });
399
        });
400
401
        describe('Remove', function() {
402
            it('should delete a existing project', async function() {
403
                const client = await getAuthenticatedTestClient();
404
                const newProject = await client.createProject({
405
                    title: 'New Project',
406
                    blocks: [],
407
                });
408
409
                const project = JSON.parse(newProject.body);
410
                const projectId = project._id;
411
412
                const response = await client.deleteProject(projectId);
413
414
                expect(response.statusCode).to.equal(204);
415
            });
416
        });
417
    });
418
419
    describe('Block', function() {
420
        var testBlockId = null;
421
422
        describe('List Project Blocks', function() {
423
            it('should list project blocks', async function() {
424
                const projectId = '5ca344b1df6272001ae7d7ac';
425
                const client = await getAuthenticatedTestClient();
426
                const response = await client.listBlocks(projectId);
427
428
                const blocks = response.json;
429
430
                expect(response.statusCode).to.equal(200);
431
                blocks.forEach(block => {
432
                    expect(block).to.matchPattern(blockSchema);
433
                });
434
            });
435
        });
436
437
        describe('Create Project Block', function() {
438
            it('should create and return a new project block', async function() {
439
                const projectId = '5ca344b1df6272001ae7d7ac';
440
441
                const client = await getAuthenticatedTestClient();
442
                const response = await client.createBlock(projectId, {
443
                    description: 'New Block',
444
                });
445
446
                const responseBody = response.json;
447
448
                expect(response.statusCode).to.equal(201);
449
                expect(responseBody).to.matchPattern(blockSchema);
450
                expect(responseBody.description).to.equal('New Block');
451
452
                testBlockId = responseBody._id;
453
            });
454
        });
455
456
        describe('Retrieve Project Block', function() {
457
            it('should return a project block', async function() {
458
                const projectId = '5ca344b1df6272001ae7d7ac';
459
                const blockId = '5cb8698632f905001a024614';
460
461
                const client = await getAuthenticatedTestClient();
462
                const response = await client.listBlock(projectId, blockId);
463
464
                const responseBody = response.json;
465
466
                expect(response.statusCode).to.equal(200);
467
                expect(responseBody).to.matchPattern(blockSchema);
468
            });
469
        });
470
471
        describe('Update Project Block', function() {
472
            it('should update and return a project block', async function() {
473
                const projectId = '5ca344b1df6272001ae7d7ac';
474
                const blockId = '5cb8698632f905001a024614';
475
476
                const client = await getAuthenticatedTestClient();
477
                const response = await client.updateBlock(projectId, blockId, {
478
                    description: 'Updated Block Description',
479
                });
480
481
                const responseBody = response.json;
482
483
                expect(response.statusCode).to.equal(200);
484
                expect(responseBody).to.matchPattern(blockSchema);
485
                expect(responseBody.description).to.equal('Updated Block Description');
486
            });
487
        });
488
489
        describe('Move Project Block Forward', function() {
490
            it('should move a project block forward (+1)', async function() {
491
                const projectId = '5ca344b1df6272001ae7d7ac';
492
493
                const client = await getAuthenticatedTestClient();
494
                const response = await client.moveBlockForward(projectId, testBlockId);
495
496
                const responseBody = response.json;
497
498
                expect(response.statusCode).to.equal(200);
499
                expect(responseBody).to.matchPattern(blockSchema);
500
            });
501
        });
502
503
        describe('Move Project Block Backward', function() {
504
            it('should move a project block forward (-1)', async function() {
505
                const projectId = '5ca344b1df6272001ae7d7ac';
506
507
                const client = await getAuthenticatedTestClient();
508
                const response = await client.moveBlockBackward(projectId, testBlockId);
509
510
                const responseBody = response.json;
511
512
                expect(response.statusCode).to.equal(200);
513
                expect(responseBody).to.matchPattern(blockSchema);
514
            });
515
        });
516
517
        describe('Clone Project Block', function() {
518
            it('should clone a project block without a specific position', async function() {
519
                const projectId = '5ca344b1df6272001ae7d7ac';
520
521
                const client = await getAuthenticatedTestClient();
522
                const response = await client.cloneBlock(projectId, testBlockId);
523
524
                const responseBody = response.json;
525
526
                expect(response.statusCode).to.equal(201);
527
                expect(responseBody).to.matchPattern(blockSchema);
528
            });
529
530
            it('should clone a project block and put it in a specific position', async function() {
531
                const projectId = '5ca344b1df6272001ae7d7ac';
532
533
                const client = await getAuthenticatedTestClient();
534
                const response = await client.cloneBlock(projectId, testBlockId, 0);
535
536
                const responseBody = response.json;
537
538
                expect(response.statusCode).to.equal(201);
539
                expect(responseBody).to.matchPattern(blockSchema);
540
            });
541
        });
542
543
        describe('Remove Project Block', function() {
544
            it('should delete a project block', async function() {
545
                const projectId = '5ca344b1df6272001ae7d7ac';
546
547
                const client = await getAuthenticatedTestClient();
548
                const response = await client.deleteBlock(projectId, testBlockId);
549
550
                expect(response.statusCode).to.equal(204);
551
            });
552
        });
553
    });
554
555
    describe('Row', function() {
556
        var testRowId = null;
557
558
        describe('List Project Block Rows', function() {
559
            it('should list project block rows', async function() {
560
                const projectId = '5ca344b1df6272001ae7d7ac';
561
                const blockId = '5cb8698632f905001a024614';
562
                const client = await getAuthenticatedTestClient();
563
                const response = await client.listRows(projectId, blockId);
564
565
                const rows = response.json;
566
567
                expect(response.statusCode).to.equal(200);
568
                rows.forEach(row => {
569
                    expect(row).to.matchPattern(rowSchema);
570
                });
571
            });
572
        });
573
574
        describe('Create Project Block Row', function() {
575
            it('should create and return a new project block row', async function() {
576
                const blockId = '5cb8698632f905001a024614';
577
                const projectId = '5ca344b1df6272001ae7d7ac';
578
                const client = await getAuthenticatedTestClient();
579
                const response = await client.createRow(projectId, blockId, {
580
                    description: 'New row',
581
                });
582
583
                const responseBody = response.json;
584
585
                expect(response.statusCode).to.equal(201);
586
                expect(responseBody).to.matchPattern(rowSchema);
587
                expect(responseBody.description).to.equal('New row');
588
589
                testRowId = responseBody._id;
590
            });
591
        });
592
593
        describe('Retrieve Project Block Row', function() {
594
            it('should list a project block row', async function() {
595
                const projectId = '5ca344b1df6272001ae7d7ac';
596
                const blockId = '5cb8698632f905001a024614';
597
                const client = await getAuthenticatedTestClient();
598
                const response = await client.listRow(projectId, blockId, testRowId);
599
600
                const responseBody = response.json;
601
602
                expect(response.statusCode).to.equal(200);
603
                expect(responseBody).to.matchPattern(rowSchema);
604
            });
605
        });
606
607
        describe('Update Project Block Row', function() {
608
            it('should update and return a project block row', async function() {
609
                const blockId = '5cb8698632f905001a024614';
610
                const projectId = '5ca344b1df6272001ae7d7ac';
611
                const client = await getAuthenticatedTestClient();
612
                const response = await client.updateRow(projectId, blockId, testRowId, {
613
                    description: 'Updated row description',
614
                });
615
616
                const responseBody = response.json;
617
618
                expect(response.statusCode).to.equal(200);
619
                expect(responseBody).to.matchPattern(rowSchema);
620
                expect(responseBody.description).to.equal('Updated row description');
621
            });
622
        });
623
624
        describe('Clone Project Block Row', function() {
625
            it('should clone a project block row without a specific position', async function() {
626
                const projectId = '5ca344b1df6272001ae7d7ac';
627
                const blockId = '5cb8698632f905001a024614';
628
629
                const client = await getAuthenticatedTestClient();
630
                const response = await client.cloneRow(projectId, blockId, testRowId);
631
632
                const responseBody = response.json;
633
634
                expect(response.statusCode).to.equal(201);
635
                expect(responseBody).to.matchPattern(rowSchema);
636
            });
637
638
            it('should clone project block row and put it in a specific position', async function() {
639
                const projectId = '5ca344b1df6272001ae7d7ac';
640
                const blockId = '5cb8698632f905001a024614';
641
642
                const client = await getAuthenticatedTestClient();
643
                const response = await client.cloneRow(projectId, blockId, testRowId, 0);
644
645
                const responseBody = response.json;
646
647
                expect(response.statusCode).to.equal(201);
648
                expect(responseBody).to.matchPattern(rowSchema);
649
            });
650
        });
651
652
        describe('Remove Project Block Row', function() {
653
            it('should delete a project block row', async function() {
654
                const projectId = '5ca344b1df6272001ae7d7ac';
655
                const blockId = '5cb8698632f905001a024614';
656
657
                const client = await getAuthenticatedTestClient();
658
                const response = await client.deleteRow(projectId, blockId, testRowId);
659
660
                expect(response.statusCode).to.equal(204);
661
            });
662
        });
663
    });
664
665
    describe('Column', function() {
666
        var testColumnId = null;
667
668
        describe('List Project Block Row Columns', function() {
669
            it('should list project block row columns', async function() {
670
                const projectId = '5ca344b1df6272001ae7d7ac';
671
                const blockId = '5cb8698632f905001a024614';
672
                const rowId = '5cbf11c97f6a64001aea65f2';
673
                const client = await getAuthenticatedTestClient();
674
                const response = await client.listColumns(projectId, blockId, rowId);
675
676
                const columns = response.json;
677
678
                expect(response.statusCode).to.equal(200);
679
                columns.forEach(column => {
680
                    expect(column).to.matchPattern(columnSchema);
681
                });
682
            });
683
        });
684
685
        describe('Create Project Block Row Column', function() {
686
            it('should create and return a new project block row column', async function() {
687
                const blockId = '5cb8698632f905001a024614';
688
                const projectId = '5ca344b1df6272001ae7d7ac';
689
                const rowId = '5cbf11c97f6a64001aea65f2';
690
                const client = await getAuthenticatedTestClient();
691
                const response = await client.createColumn(projectId, blockId, rowId, {
692
                    contents: [],
693
                    size: 12,
694
                });
695
696
                const responseBody = response.json;
697
698
                expect(response.statusCode).to.equal(201);
699
                expect(responseBody).to.matchPattern(columnSchema);
700
                expect(responseBody.size).to.equal(12);
701
702
                testColumnId = responseBody._id;
703
            });
704
        });
705
706
        describe('Retrieve Project Block Row Column', function() {
707
            it('should list a project block row column', async function() {
708
                const projectId = '5ca344b1df6272001ae7d7ac';
709
                const blockId = '5cb8698632f905001a024614';
710
                const rowId = '5cbf11c97f6a64001aea65f2';
711
                const client = await getAuthenticatedTestClient();
712
                const response = await client.listColumn(projectId, blockId, rowId, testColumnId);
713
714
                const responseBody = response.json;
715
716
                expect(response.statusCode).to.equal(200);
717
                expect(responseBody).to.matchPattern(columnSchema);
718
            });
719
        });
720
721
        describe('Update Project Block Row Column', function() {
722
            it('should update and return a project block row column', async function() {
723
                const blockId = '5cb8698632f905001a024614';
724
                const projectId = '5ca344b1df6272001ae7d7ac';
725
                const rowId = '5cbf11c97f6a64001aea65f2';
726
                const client = await getAuthenticatedTestClient();
727
                const response = await client.updateColumn(
728
                    projectId,
729
                    blockId,
730
                    rowId,
731
                    testColumnId,
732
                    {
733
                        size: 11,
734
                    }
735
                );
736
737
                const responseBody = response.json;
738
739
                expect(response.statusCode).to.equal(200);
740
                expect(responseBody).to.matchPattern(columnSchema);
741
                expect(responseBody.size).to.equal(11);
742
            });
743
        });
744
745
        describe('Remove Project Block Row Column', function() {
746
            it('should delete a project block row column', async function() {
747
                const blockId = '5cb8698632f905001a024614';
748
                const projectId = '5ca344b1df6272001ae7d7ac';
749
                const rowId = '5cbf11c97f6a64001aea65f2';
750
                const client = await getAuthenticatedTestClient();
751
752
                const response = await client.deleteColumn(projectId, blockId, rowId, testColumnId);
753
754
                expect(response.statusCode).to.equal(204);
755
            });
756
        });
757
    });
758
759
    describe('Content', function() {
760
        var testContentId = null;
761
762
        describe('List Project Block Row Column Contents', function() {
763
            it('should list project block row column contents', async function() {
764
                const projectId = '5ca344b1df6272001ae7d7ac';
765
                const blockId = '5cb8698632f905001a024614';
766
                const rowId = '5cb8698632f905001a024615';
767
                const columnId = '5cb869d132f905001a024656';
768
                const client = await getAuthenticatedTestClient();
769
                const response = await client.listContents(projectId, blockId, rowId, columnId);
770
771
                const contents = response.json;
772
773
                expect(response.statusCode).to.equal(200);
774
                contents.forEach(content => {
775
                    expect(content).to.matchPattern(contentSchema);
776
                });
777
            });
778
        });
779
780
        describe('Create Project Block Row Column Content', function() {
781
            it('should create and return a new project block row column content', async function() {
782
                const projectId = '5ca344b1df6272001ae7d7ac';
783
                const blockId = '5cb8698632f905001a024614';
784
                const rowId = '5cb8698632f905001a024615';
785
                const columnId = '5cb869d132f905001a024656';
786
                const client = await getAuthenticatedTestClient();
787
                const response = await client.createContent(projectId, blockId, rowId, columnId, {
788
                    style: {
789
                        backgroundImage: '',
790
                        backgroundRepeat: 'no-repeat',
791
                        backgroundSize: 'cover',
792
                        backgroundPosition: 'center center',
793
                        opacity: 1,
794
                    },
795
                    type: 'text',
796
                    data: {
797
                        json: {
798
                            type: 'doc',
799
                            content: [
800
                                {
801
                                    type: 'paragraph',
802
                                    content: [
803
                                        {
804
                                            type: 'text',
805
                                            text: 'Lorem Ipsum',
806
                                        },
807
                                    ],
808
                                },
809
                            ],
810
                        },
811
                        html: '<p style="text-align: center">Lorem Ipsum</p>',
812
                    },
813
                });
814
815
                const responseBody = response.json;
816
817
                expect(response.statusCode).to.equal(201);
818
                expect(responseBody).to.matchPattern(contentSchema);
819
820
                testContentId = responseBody._id;
821
            });
822
        });
823
824
        describe('Retrieve Project Block Row Column Content', function() {
825
            it('should list a project block row column content', async function() {
826
                const projectId = '5ca344b1df6272001ae7d7ac';
827
                const blockId = '5cb8698632f905001a024614';
828
                const rowId = '5cb8698632f905001a024615';
829
                const columnId = '5cb869d132f905001a024656';
830
                const client = await getAuthenticatedTestClient();
831
                const response = await client.listContent(
832
                    projectId,
833
                    blockId,
834
                    rowId,
835
                    columnId,
836
                    testContentId
837
                );
838
839
                const responseBody = response.json;
840
841
                expect(response.statusCode).to.equal(200);
842
                expect(responseBody).to.matchPattern(contentSchema);
843
            });
844
        });
845
846
        describe('Update Project Block Row Column Content', function() {
847
            it('should update and return a project block row column content', async function() {
848
                const projectId = '5ca344b1df6272001ae7d7ac';
849
                const blockId = '5cb8698632f905001a024614';
850
                const rowId = '5cb8698632f905001a024615';
851
                const columnId = '5cb869d132f905001a024656';
852
                const client = await getAuthenticatedTestClient();
853
                const response = await client.updateContent(
854
                    projectId,
855
                    blockId,
856
                    rowId,
857
                    columnId,
858
                    testContentId,
859
                    {
860
                        type: 'text',
861
                        data: {
862
                            json: {
863
                                type: 'doc',
864
                                content: [
865
                                    {
866
                                        type: 'paragraph',
867
                                        content: [
868
                                            {
869
                                                type: 'text',
870
                                                text: 'Lorem Ipsuma',
871
                                            },
872
                                        ],
873
                                    },
874
                                ],
875
                            },
876
                            html: '<p style="text-align: center">Lorem Ipsuma</p>',
877
                        },
878
                    }
879
                );
880
881
                const responseBody = response.json;
882
883
                expect(response.statusCode).to.equal(200);
884
                expect(responseBody).to.matchPattern(contentSchema);
885
            });
886
        });
887
888
        describe('Remove Project Block Row Column Content', function() {
889
            it('should delete a project block row column', async function() {
890
                const projectId = '5ca344b1df6272001ae7d7ac';
891
                const blockId = '5cb8698632f905001a024614';
892
                const rowId = '5cb8698632f905001a024615';
893
                const columnId = '5cb869d132f905001a024656';
894
                const client = await getAuthenticatedTestClient();
895
                const response = await client.deleteContent(
896
                    projectId,
897
                    blockId,
898
                    rowId,
899
                    columnId,
900
                    testContentId
901
                );
902
903
                expect(response.statusCode).to.equal(204);
904
            });
905
        });
906
    });
907
});
908